package zhao.lulu.refer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.Result;

import javax.servlet.http.HttpSession;

@RestController
public class HttpSessionSet {
    @Autowired
    private HttpSession session;
    @RequestMapping("/loginTest1")
    public Result loginTest1(){
        session.setAttribute("isLogin",true);
        return Result.success();
    }
    @GetMapping("/loginTest2")
    public Result loginTest2(){
        Boolean  isLogin = ( Boolean)session.getAttribute("isLogin");
        if(isLogin==null || isLogin==false){
            return Result.error("未登录，不能访问资源。");
        }else{
            return Result.success("登录成功，可以访问资源");
        }

    }
}










